/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 * 作者:吕艳阳
 */

import React from 'react';
import {Card, Descriptions, Drawer, Spin, Tabs} from 'antd';
import styles from '@/utils/utils.less'
import service from '../service';
import HistoryLogTable from '@/components/HistoryLog';
import {DetailsDialogProps} from "@/global";
import {ParamModel} from "@/pages/sys/param/data";
import useLoad from "@/hooks/useLoad";

const {TabPane} = Tabs;

/** 系统参数详情组件 */
const Details: React.FC<DetailsDialogProps> = props => {
  const {params: {id}, visible, hide} = props;
  const {loading, data: model} = useLoad<ParamModel>({
    isLoad: Boolean(id),
    onLoad: () => service.selectById(id),
  }, [id]);

  return (
    <Drawer
      title="查看系统参数详细信息"
      width="50%"
      visible={visible}
      onClose={hide}
      destroyOnClose
      className={styles.drawerBodyPadding}
    >
      <Spin spinning={loading} wrapperClassName={styles.h100p}>
        <Tabs className={styles.drawerBodyTabsPadding}>
          <TabPane tab="基本信息" key="basic">
            {model && (<Basic model={model}/>)}
          </TabPane>
          <TabPane tab="操作日志" key="history">
            {model && (<HistoryLogTable tableName="SysParam" primaryKey={model.id}/>)}
          </TabPane>
        </Tabs>
      </Spin>
    </Drawer>
  );
};

function Basic(props: { model: ParamModel }) {
  const {model} = props;
  return (
    <Card bordered={false} className={styles.cardBodyDesc}>
      <Descriptions column={1} bordered={true} size="small" className={styles.detailsDescriptions}>
        <Descriptions.Item label="主键">{model.id}</Descriptions.Item>
        <Descriptions.Item label="参数名称">{model.name}</Descriptions.Item>
        <Descriptions.Item label="参数编码">{model.code}</Descriptions.Item>
        <Descriptions.Item label="参数分类">{model.categoryName}</Descriptions.Item>
        <Descriptions.Item label="参数值">{model.value}</Descriptions.Item>
        <Descriptions.Item label="备注">{model.remark}</Descriptions.Item>
      </Descriptions>
    </Card>
  );
}

export default React.memo(Details);
